package cifreRomane;

import java.awt.Component;
import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;

import cifreRomane.Context;
import arab.Cincizeci;
import arab.Unu;
import arab.Cinci;
import arab.Cincisute;
import arab.Mie;
import arab.Suta;
import arab.Zece;
import arab.ExpresieNula;
import arab.ExpresieAbstracta;
import cifreRomane.Context;

public class Main extends JFrame implements ActionListener {
	JButton submit;
	JTextField parametru;
	JTextField rezultat;
	
	public void creareMediuGrafic(){
		JFrame fereastra=new JFrame();
		fereastra.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		fereastra.setAlwaysOnTop(true);
		Container suprafata=fereastra.getContentPane();
		suprafata.setLayout(new BoxLayout(suprafata,BoxLayout.Y_AXIS));
		JLabel info=new JLabel("Introduceti numarul in cifre romane:");
		info.setAlignmentX(Component.CENTER_ALIGNMENT);
		suprafata.add(info);
	
	parametru=new JTextField(12);
	parametru.setAlignmentX(Component.CENTER_ALIGNMENT);
	suprafata.add(parametru);
	submit=new JButton("Calculeaza");
	submit.setAlignmentX(Component.CENTER_ALIGNMENT);
	suprafata.add(submit);
	submit.addActionListener(this);
	rezultat=new JTextField(12);
	rezultat.setAlignmentX(Component.CENTER_ALIGNMENT);
	suprafata.add(rezultat);
	rezultat.setEditable(false);
	fereastra.pack();
	fereastra.setVisible(true);
	}
	
	public void actionPerformed(ActionEvent event) {
		if (event.getSource().equals(submit)){
		rezultat.setText(calculat(parametru.getText()));
		}
		}
	public String calculat(String sirPars){
		Context rezultat = new Context();
		sirPars = sirPars.toUpperCase();
		char[] lista = sirPars.toCharArray();
		for (char c : lista) {
			ExpresieAbstracta expr = new ExpresieNula();
			switch (c) {
			case 'I':
				expr = new Unu();
				break;
			case 'V':
				expr = new Cinci();
				break;
			case 'X':
				expr = new Zece();
				break;
			case 'L':
				expr = new Cincizeci();
				break;
			case 'C':
				expr = new Suta();
			break;
			case 'D':
				expr = new Cincisute();
				break;
			case 'M':
				expr = new Mie();
				break;
		}
		expr.interpretor(rezultat);
	}
	return String.valueOf(rezultat.returneazaFinal());
}
public static void main(String[]args){
Main m = new Main();
m.creareMediuGrafic();
}

}
